# import win32api, win32con, win32gui
from base64 import encode
import uuid
from xmlrpc.client import boolean
import yaml
import os
import pyautogui
import time
import datetime  # 导入datetime模块
import threading  # 导入threading模块
from paddleocr import PaddleOCR
from PIL import Image
from PIL import ImageGrab
import cv2
import numpy as np
# 自写外部类
import count
import imgCompare

# 斗鸡自动失败，需要先在阵容里放一个没有技能的角色 然后在battles里面设置最大次数 

# 读取配置文件


def dict2namespace():
    with open('config.yml', 'r', encoding='utf-8') as f:
        data = yaml.load(f, Loader=yaml.FullLoader)
        return data
 
  

def battles():  # 定义方法
    for num in range(1,90):
        print('第'+str(num)+"次斗鸡") 
        # 跳转按钮 进入选人列表
        # print("移动到挑战按钮") 
        pyautogui.moveTo(configs['location']['btn']['tiaozhan']
                         ['x'], configs['location']['btn']['tiaozhan']['y'])
        # 跳转按钮
        pyautogui.click()
        time.sleep(0.5)
        # 进入战斗
        pyautogui.moveTo(configs['location']['btn']['tiaozhan3']
                         ['x'], configs['location']['btn']['tiaozhan3']['y'])
        # 进入战斗
        # print("进入战斗") 
        pyautogui.click()
        time.sleep(4)
        # 撤退
        # print("移动到撤退按钮") 
        pyautogui.moveTo(configs['location']['btn']['out']
                         ['x'], configs['location']['btn']['out']['y'])
        pyautogui.click()
        time.sleep(0.5)
        # print("撤退确认") 
        pyautogui.moveTo(configs['location']['btn']['outConfirm']
                         ['x'], configs['location']['btn']['outConfirm']['y'])
        pyautogui.click()
    
        # print("等待结算页面") 
        pyautogui.moveTo(configs['location']['btn']['out']
                         ['x'], configs['location']['btn']['out']['y'])
        time.sleep(3)
        # print("退出斗鸡") 
        pyautogui.click()
        # print("等待下一场") 

        time.sleep(2)


if __name__ == "__main__":
    configs = dict2namespace()
    # t1 = threading.Timer(1, function=job)  # 创建定时器
    # t1.start()  # 开始执行线程
    battles()
